#include "stdafx.h"
#include "resource.h"
#include <sstream>

#include "IdoComplete.h"

namespace quicks {
	
	void MatchStringToWString(const matchstring& ms, wstring& ws) {
		ws.clear();
		ws.reserve(ms.size());
		for (matchstring::const_iterator it = ms.begin(); it != ms.end(); it++) {
			ws.push_back(it->c);
		}
	}
	void WStringToMatchStringUnMatched(const wstring& ws, matchstring& ms) {
		ms.clear();
		ms.reserve(ws.size());
		for (wstring::const_iterator it = ws.begin(); it != ws.end(); it++) {
			matchchar_t c;
			c.c = *it;
			c.matches = false;
			ms.push_back(c);
		}
	}
	/*
	IdoComplete<class T>::IdoComplete() {}
	IdoComplete<class T>::~IdoComplete() {}
	IdoComplete<class T>::IdoComplete() {
		// initialize the matrix
		m_mat = new TCHAR*[MAXSIZE];
		for (int i = 0; i < MAXSIZE; i++) {
			m_mat[i] = new TCHAR[MAXSIZE];
		}
	}
	IdoComplete<class T>::~IdoComplete() {
		for (int i = 0; i < MAXSIZE; i++) {
			delete[] m_mat[i];
		}
		delete[] m_mat;
	}

	void IdoComplete<class T>::MatchInput(const std::wstring& key) {
		std::wstring res;
		int nMax = 0;
		
		for (std::vector<Item<T>>::const_iterator it = m_items.begin(); it != m_items.end(); it++) {
			int nCur = InnerMatch(key, *it, 0);
			if (nCur > nMax) {
				res = it->text;
				nMax = nCur;
			}
		}
		
	}

	void IdoComplete<class T>::Add(std::wstring entry, const T& data) {

	}
	int InnerMatch(const std::wstring& key, const std::wstring& hole, int streak) {

		// if we ate the key before the whole, then score > 0
		if (key.size() == 0)
			return streak;
		// if we ate the hole before the key, then score = 0
		if (hole.size() == 0)
			return 0;

		// if this character matches, take the max of using the key here,
		// or using it later.

		if (key[0] == hole[0]) {

			// match them, eat both
			int s1 = InnerMatch(key.substr(1), hole.substr(1), streak + 1);
			// no match, move on
			int s2 = InnerMatch(key, hole.substr(1), 0);
			if (s2 > s1) {
				// was better not to match
				return s2;
			}
			// matching was better
			return s1 + streak;
		}
		// no match, move on
		return InnerMatch(key, hole.substr(1), 0);
	}
	*/
}